<?php

namespace Api\Model;

use Think\Model;

class UserLikeShopModel extends Model {

    /**
     * @name 保存喜欢的商家
     */
    public function saveFavoriteBusiness($userid, $shop = array()) {
        $this->where("`user_id`={$userid}")->delete();
        foreach ($shop as $key => $val) {
            $data = array('user_id' => $userid, 'shop_id' => $val);
            $this->add($data);
        }
    }

    /**
     * @name 获取喜欢的商家
     */
    public function getFavoriteBusiness($userid) {
        $result = $this->alias('s')->field("sp.id,sp.name")->join("__SHOPS__  as sp ON s.shop_id = sp.id", 'LEFT')->where("s.user_id={$userid}")->select();
        return $result;
    }

}